package com.wc.alorithm_blue_bridge._前缀和与差分.Q3829;


import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/11/22 13:16
 * @description 大石头的搬运工
 * https://www.lanqiao.cn/problems/3829/learning/?page=1&first_category_id=1
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Stone[] stones = new Stone[n + 2];
        stones[0] = new Stone(0, 0);
        for (int i = 1; i <= n; i++) {
            Stone stone = new Stone();
            stones[i] = stone;
            stone.w = sc.nextInt();
            stone.p = sc.nextInt();
        }
        stones[n + 1] = new Stone(0, 0);
        Arrays.sort(stones, 1, n + 1);
        /**
         * pre[i] 表示 前 i 个到达i的总费用
         */
        long[] pre = new long[n + 2];
        /**
         * next[i] 表示后面的石头移动到i的总费用
         */
        long[] next = new long[n + 2];
        long wSum = 0;
        for (int i = 1; i <= n; i++) {
            pre[i] = pre[i - 1];
            pre[i] += wSum * (stones[i].p - stones[i - 1].p);
            wSum += stones[i].w;
        }
        wSum = 0;
        for (int i = n; i >= 1; i--) {
            next[i] = next[i + 1];
            next[i] += wSum * (stones[i + 1].p - stones[i].p);
            wSum += stones[i].w;
        }

        long ans = Long.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            ans = Math.min(ans, pre[i] + next[i]);
        }

        System.out.println(ans);
    }

    static class Stone implements Comparable<Stone> {
        int w, p;

        public Stone() {

        }

        public Stone(int w, int p) {
            this.w = w;
            this.p = p;
        }


        @Override
        public int compareTo(Stone o) {
            return this.p - o.p;
        }
    }
}
